package com.zh.web.openApi;

import com.zh.common.exception.BusinessException;
import com.zh.web.base.ApiResult;
import com.zh.web.config.DefaultFeignConfig;
import com.zh.web.domain.auth.dto.AddRole2UserDto;
import com.zh.web.domain.auth.dto.DelRole2UserDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@FeignClient(name = "ls-service-auth", path = "/auth", configuration = DefaultFeignConfig.class, contextId = "authClient", fallback = AuthClientFallback.class)
public interface AuthClient {

    @GetMapping("/getPublicKey")
    ApiResult<String> getPublicKey();

    @GetMapping("/getPrivateKey")
    ApiResult<String> getPrivateKey();

    @GetMapping("/getSessionByToken")
    ApiResult<Map<String, Object>> getSessionByToken(@RequestParam("token") String token);

    @GetMapping("/logout")
    ApiResult<String> logout(@RequestParam String authToken);

    @PostMapping("/role2User/add")
    ApiResult<String> addRole2User(@RequestBody AddRole2UserDto addRole2UserDto);

    @DeleteMapping("/role2User/delete")
    ApiResult<String> delRole2User(@RequestBody DelRole2UserDto delRole2UserDto);

    @GetMapping("/system/clearAllExpiredData")
    ApiResult<String> clearAllExpiredData();
}

class AuthClientFallback implements AuthClient {

    @Override
    public ApiResult<String> getPublicKey() {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<String> getPrivateKey() {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<Map<String, Object>> getSessionByToken(String token) {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<String> logout(String token) {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<String> addRole2User(AddRole2UserDto addRole2UserDto) {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<String> delRole2User(DelRole2UserDto delRole2UserDto) {
        throw new BusinessException("系统繁忙");
    }

    @Override
    public ApiResult<String> clearAllExpiredData() {
        throw new BusinessException("系统繁忙");
    }
}